<!DOCTYPE html>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>优惠券编辑</title>
  <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
  <link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
</head>
<body>
		<div class="layui-panel"style="padding: 8px;">
		    <fieldset class="layui-elem-field layui-border-green">
		        <legend>信息</legend>
		        <form class="layui-form layui-form-pane" style="margin: 20px;">
		            <div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">名称</label>
							<div class="layui-input-inline">
								<input class="layui-input" type="text" name="name"autocomplete="off" />
							</div>
						</div>
						<div class="layui-inline">
							<div class="layui-input-inline">
								<a class="layui-btn layui-btn-primary"lay-submit="" lay-filter="searchBtn">
									<li class="layui-icon layui-icon-search">搜索</li>
								</a>
							</div>
						</div>
					</div>
		        </form>
		    </fieldset>
		  </div>
		  
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
</fieldset>
<form class="layui-form layui-form-pane" action="">
  <input type="hidden" name="id" th:value="${c.id}">
    <div class="layui-form-item">
    <label class="layui-form-label">名称</label>
    <div class="layui-input-block">
      <select name="name"  lay-filter="name" lay-verify="required">
        <option value="0">可兑换优惠券</option>
        <option value="1" >限时减满券</option>
        <option value="2">新用户优惠券</option>
      </select>
    </div>
  </div>
  
    <div class="layui-form-item">
    <label class="layui-form-label">详情介绍</label>
    <div class="layui-input-block">
      <select name="introduce"  lay-filter="introduce"lay-verify="required">
        <option value="0">全场通用</option>
        <option value="1" selected="">仅限部分活动使用</option>
      </select>
    </div>
  </div>
  
    <div class="layui-form-item">
    <label class="layui-form-label">标签</label>
    <div class="layui-input-block">
      <select name="label"  lay-filter="label"lay-verify="required">
        <option value="0">仅兑换领券</option>
        <option value="1" selected="">无限制</option>
      </select>
    </div>
  </div>
  
    <div class="layui-form-item">
    <label class="layui-form-label">优惠券类型</label>
    <div class="layui-input-block">
      <select id="type" name="type" lay-filter="types" lay-verify="required">
        <option value="0" selected="" >兑换码</option>
        <option value="1" >通用领券</option>
        <option value="2">注册赠券</option>
      </select>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">最低消费</label>
    <div class="layui-input-inline">
      <input type="text" name="minConsume"th:value="${c.minConsume}"  lay-verify="required||limits" placeholder="请输入数量" autocomplete="off" class="layui-input">
    </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label">优惠面值</label>
    <div class="layui-input-inline">
      <input type="text" name="reduction" th:value="${c.reduction}" lay-verify="required||limits" placeholder="请输入数量" autocomplete="off" class="layui-input">
    </div>
  </div>

  
    <div class="layui-form-item">
    <label class="layui-form-label">每人限额</label>
    <div class="layui-input-inline">
      <input type="text" name="limits" th:value="${c.limits}" lay-verify="required||limits" placeholder="请输入数量" autocomplete="off" class="layui-input">
    </div>
  </div>
   <div class="layui-form-item" >
    <label class="layui-form-label">当前状态</label>
    <div class="layui-input-block" >
      <input type="radio" name="status" th:if="${c.status} eq 0" value="0"  title="正常" checked="">

      <input type="radio" name="status" th:if="${c.status} eq 1" value="1"  title="已过期"checked="">
    </div>
  </div>
  
  
    <div class="layui-form-item">
    <label class="layui-form-label">商品范围</label>
    <div class="layui-input-block">
      <select name="area"   lay-filter="area"lay-verify="required">
        <option value="0">指定商品</option>
        <option value="1" selected="">全场通用</option>
      </select>
    </div>
  </div>
  
 
  
  <div class="layui-form">
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">日期范围</label>
      <div class="layui-inline" id="Vdate">
        <div class="layui-input-inline">
          <input type="text" autocomplete="off" id="startTime"  name="startTime" class="layui-input" placeholder="开始日期">
        </div>
        <div class="layui-form-mid">-</div>
        <div class="layui-input-inline">
          <input type="text" autocomplete="off" id="endTime" name="endTime"  class="layui-input" placeholder="结束日期">
        </div>
      </div>
    </div>
  </div>
</div>


   <div class="layui-form-item">
    <label class="layui-form-label">优惠兑换码</label>
    <div class="layui-input-inline">
      <input id="code" type="text" name="code" th:value="${c.code}"  lay-verify="code" autocomplete="off" placeholder="请输入兑换码" class="layui-input">
    </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label">数量限制</label>
    <div class="layui-input-block">
      <input type="checkbox"  id="checkBtn" th:value="${c.number}" name="number" lay-skin="switch" lay-filter="switchTest" lay-text="无限制|有限制">
    </div>
  </div>

  <div class="layui-form-item">
    <button style="display: none" class="layui-btn" lay-submit="" lay-filter="submitBtn2"id="submitBtn2">确定</button>
  </div>
</form>
          
<script>
  var $;
layui.use(['form', 'laydate','jquery'], function(){
  var form = layui.form,
  layer = layui.layer,
  laydate = layui.laydate;
  $=layui.jquery;
  //日期

   laydate.render({
    elem: '#Vdate'
    //设置开始日期、日期日期的 input 选择器
    //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
    ,range: ['#startTime', '#endTime']
  });


  //自定义验证规则
  form.verify({
    code: [
      /^[^\u4e00-\u9fa5]{2,12}$/
      ,'兑换码必须2到12位，且不能出现中文和空格'
    ],
    limits:[
      /^[\d]{1,12}$/
      ,'数量必须1到12位，且不能出现空格'
    ]
  });


  form.on("select(types)",function (data){
         disCode(data);
  })

  //监听指定开关
  form.on('switch(switchTest)', function(data){
     if (data.value==1){
       $('#checkBtn').val(0);
       //layer.msg("当前开关为"+data.value);
     }
    else if (data.value==0){
      $('#checkBtn').val(1);
      //layer.msg("当前开关为"+data.value);
    }
    else {
       $('#checkBtn').val(1);
       //layer.msg("默认开关为"+data.value);
     }
  });

 function disCode(data){
    var lev=data.value;
    if(lev!=0){
      $('#code').attr("disabled","disabled");
      $('#code').hide();
    }
    else {
      $('#code').removeAttr("disabled")
      $('#code').show();
    }
  }





  form.on('submit(submitBtn2)',function (data) {
    var formData = data.field;
    console.log(formData)
    $.ajax({
      type:'get',
      url:'/system/cp/update',
      data:formData,
      dataType:'json',
      success:function (result) {
        if(result.is){
          let index = parent.layer.getFrameIndex(window.name);
          parent.layer.close(index);//关闭父页面窗口
        }
      }
    })
  })

  
});
function btnSubmit23() {
  $("#submitBtn2").click();
}


</script>

</body>
</html>